package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ArticleConfigService;
import com.heima.model.article.pojos.ApArticleConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
@Slf4j
public class ArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ArticleConfigService {
    /**
     * app端文章上下架
     *
     * @param map
     */
    @Override
    public void updateByMap(Map map) {
        //2、得到文章id
        Long articleId = Long.valueOf(map.get("articleId").toString());
        //3、得到状态
        Object enable = map.get("enable");
        //4、处理状态
        boolean isDown = !enable.equals(1);
        //5、修改文章配置表
        update(Wrappers.<ApArticleConfig>lambdaUpdate()
                .eq(ApArticleConfig::getArticleId,articleId)
                .set(ApArticleConfig::getIsDown,isDown));
    }
}
